package com.stockz.ui.swing.core;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

import org.springframework.stereotype.Component;

import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyKrupp;
import com.stockz.ui.resource.image.ImageIconLoader;
import com.stockz.ui.swing.charting.util.SwingUtil;
import com.stockz.ui.swing.widget.JLabel;

@Component
public class MainFrame extends JFrame {
	private static final long serialVersionUID = -8551022152139659367L;

	private static MainFrame instance;
	
	private final JDesktopPane desktop = new JDesktopPane();
	private final JLabel messageLabel = new JLabel("Welcome");

	public JLabel getMessageLabel() {
		return messageLabel;
	}

	public static MainFrame getInstance(){
		return instance;
	}
	
	public MainFrame() {
		super("Stockz");
		if(instance != null){
			throw new UnsupportedOperationException();
		}
		instance = this;
	}
	
	
	
	
	public void construct(){
		this.setFont(SwingUtil.mediumFont);
		setIconImage(ImageIconLoader.loadImage("icon.jpg"));
	try {
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			//UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel");
			UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticLookAndFeel");
			//PlasticLookAndFeel.setCurrentTheme(theme)MyCurrentTheme(new DesertBlue());
			PlasticLookAndFeel.setPlasticTheme(new SkyKrupp());
			//PlasticLookAndFeel.setCurrentTheme(new OceanTheme());
			//UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
			//UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Rectangle maxBounds = SwingUtil.getScreenSize();
        setMaximizedBounds(maxBounds);
        Dimension maxDimension = new Dimension(maxBounds.width/3,maxBounds.height/3);
        setMaximumSize(maxDimension);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
		setPreferredSize(maxDimension);
		
		desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		add(desktop,BorderLayout.CENTER);
		JPanel messagePanel = new JPanel();
		messagePanel.add(messageLabel,BorderLayout.CENTER);
		add(messagePanel, BorderLayout.SOUTH);
		setVisible(true);
	}

	public void add(View view){
		desktop.add(view);
		view.showAtFront();
	}
	
}
